package com.example.autumn.listener;

import org.springframework.amqp.core.ExchangeTypes;
import org.springframework.amqp.rabbit.annotation.Exchange;
import org.springframework.amqp.rabbit.annotation.Queue;
import org.springframework.amqp.rabbit.annotation.QueueBinding;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.stereotype.Component;

import java.util.Map;

/**
 * @author Liaorun
 */
@Component
public class MoyuRabbitListener {

    @RabbitListener(queues = "fanout.queue1")
    public void listenFanoutQueue1(String msg) {

        System.out.println("msg1 = " + msg);
    }


    @RabbitListener(queues = "fanout.queue2")
    public void listenFanoutQueue2(String msg) {

        System.out.println("msg2 = " + msg);
    }


    @RabbitListener(bindings = {@QueueBinding(value = @Queue(name = "direct.queue1"), exchange = @Exchange(name = "itcast.direct"), key = {"red", "blue"})})
    public void listenDirectQueue1(String msg) {
        System.out.println("msg red or blue = " + msg);
    }

    @RabbitListener(bindings = {@QueueBinding(value = @Queue(name = "direct.queue2"), exchange = @Exchange(name = "itcast.direct"), key = {"red", "yellow"})})
    public void listenDirectQueue2(String msg) {
        System.out.println("msg red or yellow = " + msg);
    }


    @RabbitListener(bindings = {@QueueBinding(value = @Queue(name = "topic.queue1"), exchange = @Exchange(name = "itcast.topic", type = ExchangeTypes.TOPIC), key = {"china.#"})})
    public void listenTopicQueue1(String msg) {

        System.out.println("msg 中国的消息 = " + msg);
    }

    @RabbitListener(bindings = {@QueueBinding(value = @Queue(name = "topic.queue2"), exchange = @Exchange(name = "itcast.topic", type = ExchangeTypes.TOPIC), key = {"#.news"})})
    public void listenTopicQueue2(String msg) {

        System.out.println("msg 所有的新闻 = " + msg);
    }


    @RabbitListener(queues = "simple.queue")
    public void listenObjectQueue(Map<String, Object> msg) {
        System.out.println("接收到simple.queue的消息：" + msg);
    }
}
